2 Problem: 11116 - Babel towers
3 (From the UVa Online Judge)
5 Author: Andrés Mejía-Posada
14 const double EPS
= 10E-9;
20 //Represents a mass "m" with center of mass at point ("x", "y")
24 mass(double X
, double Y
, double M
) : x(X
), y(Y
), m(M
){}
28 //Returns the new mass formed by combining both masses "a" and "b" into a punctual mass.
29 mass
operator | (const mass
&a
, const mass
&b
){
31 r
.x
= (a
.x
* a
.m
+ b
.x
* b
.m
) / (a
.m
+ b
.m
);
32 r
.y
= (a
.y
* a
.m
+ b
.y
* b
.m
) / (a
.m
+ b
.m
);
37 //True if the center of mass of "C" is outside the base of disc "D"
38 inline bool outside(const mass
&c
, const disc
&d
){
39 return (c
.x
-d
.x
)*(c
.x
-d
.x
) + (c
.y
-d
.y
)*(c
.y
-d
.y
) > d
.r
*d
.r
- EPS
;
44 while (cin
>> n
&& n
){
47 for (int i
=0; i
<n
; ++i
){
48 cin
>> d
[i
].x
>> d
[i
].y
>> d
[i
].r
;
53 for (int j
=1; j
< n
&& ok
; ++j
){
54 mass
c(d
[j
].x
, d
[j
].y
, d
[j
].r
* d
[j
].r
);
56 for (int i
=j
-1; i
>= 0 && ok
; --i
){
57 if (outside(c
, d
[i
])){
61 c
= c
| mass(d
[i
].x
, d
[i
].y
, d
[i
].r
*d
[i
].r
);
65 cout
<< (ok
?"F":"Unf") << "easible";
66 if (!ok
) cout
<< " " << k
;